//
//  UILabel+WNExpand.m
//  iOSOCProjectDirectory
//
//  Created by BHmac on 2017/6/9.
//  Copyright © 2017年 XieXuan. All rights reserved.
//

#import "UILabel+WNExpand.h"

@implementation UILabel (WNExpand)

-(void)labelAlightLeftAndRight
{
    [self labelAlightLeftAndRightWithWidthFrame:self.frame];
}

-(void)labelAlightLeftAndRightWithWidthFrame:(CGRect)frame
{
    //自适应高度
    CGSize textSize = [self.text boundingRectWithSize:CGSizeMake(frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine| NSStringDrawingUsesFontLeading  attributes:@{NSFontAttributeName :self.font} context:nil].size;
    CGFloat margin = (frame.size.width - textSize.width)/(self.text.length - 1);
    NSNumber *number = [NSNumber numberWithFloat:margin];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:self.text];
    //字间距 :NSKernAttributeName
    [attribute addAttribute:NSKernAttributeName value:number range:NSMakeRange(0, self.text.length - 1)];
    self.attributedText = attribute;
    
}


@end
